package com.example.PolimiAssistant.adapters;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;
import com.Wsdl2Code.WebServices.PolimiAssistant.UserCurrentSchedule;
import com.example.PolimiAssistant.R;

import java.util.ArrayList;

/**
 * Created by alejo on 7/2/14.
 */
public class AcademicScheduleListAdapter extends ArrayAdapter<UserCurrentSchedule> {

    /**
     * The list of the group names
     */
    private ArrayList<UserCurrentSchedule> scheduleList;

    /**
     * The layout inflater to dynamically allocate the layout
     */
    private LayoutInflater layoutInflater;

    public AcademicScheduleListAdapter(Context context, ArrayList<UserCurrentSchedule> list) {

        super(context, R.layout.academic_schedule_list_item, list);
        this.scheduleList = list;
    }

    public void setInflater(LayoutInflater inflater) {
        layoutInflater = inflater;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent)
    {
        //1. Set the view to use the predefine item layout
        if(convertView==null)
        {
            convertView = layoutInflater.inflate(
                    R.layout.academic_schedule_list_item, parent, false);
        }

        //2. Extract the item description or object
        UserCurrentSchedule courseSchedule = scheduleList.get(position);

        //3. Extract the item view to modify
        TextView courseName;
        TextView courseClassroom;
        TextView courseInitTime;
        TextView courseEndTime;
        TextView courseConflicts;

        courseName =(TextView)convertView.findViewById(R.id.academic_schedule_course_name);
        courseClassroom =(TextView)convertView.findViewById(R.id.academic_schedule_course_classroom);
        courseInitTime =(TextView)convertView.findViewById(R.id.academic_schedule_init_time);
        courseEndTime =(TextView)convertView.findViewById(R.id.academic_schedule_end_time);
        courseConflicts =(TextView)convertView.findViewById(R.id.academic_schedule_course_conflict_names);

        //4. Insert data for the item view
        courseName.setText(courseSchedule.name);
        courseClassroom.setText(courseSchedule.classroom_nameField);
        courseInitTime.setText(courseSchedule.start_time.substring(0, 5));
        courseEndTime.setText(courseSchedule.stop_time.substring(0, 5));
        courseConflicts.setText("No conflicts");

        return convertView;
    }
}
